import 'package:yqmssa_app/request/http_path.dart';
import 'package:yqmssa_app/request/my_request.dart';

import 'login_entity.dart';

class AppDlRequest {
  AppDlRequest._();

  ///发送验证码
  static Future sendPhoneCode(String phone) async {
    final data = {
      'phone': phone,
      'type': 1,
    };
    final res = await MyRequest().dioReq(HttpPath.getCode, data: data);
    return res;
  }

  ///注册并且登录
  static Future<LoginEntity> appLogin(Map<String, dynamic> putData) async {
    final data = {'nickName': "name", ...putData};
    final res = await MyRequest().dioReq(HttpPath.appLogin, data: data);
    return LoginEntity.fromJson(res["data"]);
  }

  ///激活
  static Future activation(Map<String, dynamic> putData) async {
    final res = await MyRequest().dioReq(HttpPath.appJh, data: putData);
    return res;
  }
}

class LoginDM {
  late final String token;
  late final bool isHavingInfo;
  late final String avatar;

  LoginDM.fromJson(Map<String, dynamic> json) {
    token = json['token'];
    isHavingInfo = json['is_having_info'];
    avatar = json['avatars'];
  }

  Map<String, dynamic> toJson() {
    final data = <String, dynamic>{};
    data['token'] = token;
    data['is_having_info'] = isHavingInfo;
    data['avatars'] = avatar;
    return data;
  }
}
